<?php require_once('Connections/RecursosHumanos.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO rol_transaccion (ID_ROL, ID_TRANSACCION) VALUES (%s, %s)",
                       GetSQLValueString($_POST['ID_ROL'], "text"),
                       GetSQLValueString($_POST['ID_TRANSACCION'], "text"));

  mysql_select_db($database_RecursosHumanos, $RecursosHumanos);
  $Result1 = mysql_query($insertSQL, $RecursosHumanos) or die(mysql_error());
}

mysql_select_db($database_RecursosHumanos, $RecursosHumanos);
$query_Rol = "SELECT rol.ID_ROL, rol.DES_ROL FROM rol ORDER BY rol.ID_ROL";
$Rol = mysql_query($query_Rol, $RecursosHumanos) or die(mysql_error());
$row_Rol = mysql_fetch_assoc($Rol);
$totalRows_Rol = mysql_num_rows($Rol);

mysql_select_db($database_RecursosHumanos, $RecursosHumanos);
$query_Transaccion = "SELECT transaccion.ID_TRANSACCION, transaccion.DES_TRANSACCION FROM transaccion ORDER BY transaccion.ID_TRANSACCION";
$Transaccion = mysql_query($query_Transaccion, $RecursosHumanos) or die(mysql_error());
$row_Transaccion = mysql_fetch_assoc($Transaccion);
$totalRows_Transaccion = mysql_num_rows($Transaccion);

$maxRows_Rol_Trans = 10;
$pageNum_Rol_Trans = 0;
if (isset($_GET['pageNum_Rol_Trans'])) {
  $pageNum_Rol_Trans = $_GET['pageNum_Rol_Trans'];
}
$startRow_Rol_Trans = $pageNum_Rol_Trans * $maxRows_Rol_Trans;

mysql_select_db($database_RecursosHumanos, $RecursosHumanos);
$query_Rol_Trans = "SELECT rol_transaccion.ID_ROL, rol.DES_ROL, rol_transaccion.ID_TRANSACCION, transaccion.DES_TRANSACCION FROM rol_transaccion, rol, transaccion WHERE rol_transaccion.ID_ROL = rol.ID_ROL  AND rol_transaccion.ID_TRANSACCION = transaccion.ID_TRANSACCION ORDER BY rol_transaccion.ID_ROL, rol_transaccion.ID_TRANSACCION";
$query_limit_Rol_Trans = sprintf("%s LIMIT %d, %d", $query_Rol_Trans, $startRow_Rol_Trans, $maxRows_Rol_Trans);
$Rol_Trans = mysql_query($query_limit_Rol_Trans, $RecursosHumanos) or die(mysql_error());
$row_Rol_Trans = mysql_fetch_assoc($Rol_Trans);

if (isset($_GET['totalRows_Rol_Trans'])) {
  $totalRows_Rol_Trans = $_GET['totalRows_Rol_Trans'];
} else {
  $all_Rol_Trans = mysql_query($query_Rol_Trans);
  $totalRows_Rol_Trans = mysql_num_rows($all_Rol_Trans);
}
$totalPages_Rol_Trans = ceil($totalRows_Rol_Trans/$maxRows_Rol_Trans)-1;

$queryString_Rol_Trans = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Rol_Trans") == false && 
        stristr($param, "totalRows_Rol_Trans") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Rol_Trans = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Rol_Trans = sprintf("&totalRows_Rol_Trans=%d%s", $totalRows_Rol_Trans, $queryString_Rol_Trans);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
body {
	margin-left: 2cm;
	margin-top: 1cm;
}
.Estilo1 {font-size: 12px}
-->
</style></head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <p><a href="home.html">REGRESAR</a></p>
  <table align="left">
    <tr valign="baseline">
      <td nowrap align="right">ID_ROL:</td>
      <td><select name="ID_ROL">
        <option value=""></option>
        <?php
do {  
?>
        <option value="<?php echo $row_Rol['ID_ROL']?>"><?php echo $row_Rol['DES_ROL']?></option>
          <?php
} while ($row_Rol = mysql_fetch_assoc($Rol));
  $rows = mysql_num_rows($Rol);
  if($rows > 0) {
      mysql_data_seek($Rol, 0);
	  $row_Rol = mysql_fetch_assoc($Rol);
  }
?>
      </select>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">ID_TRANSACCION:</td>
      <td><select name="ID_TRANSACCION">
        <option value=""></option>
        <?php
do {  
?>
        <option value="<?php echo $row_Transaccion['ID_TRANSACCION']?>"><?php echo $row_Transaccion['DES_TRANSACCION']?></option>
          <?php
} while ($row_Transaccion = mysql_fetch_assoc($Transaccion));
  $rows = mysql_num_rows($Transaccion);
  if($rows > 0) {
      mysql_data_seek($Transaccion, 0);
	  $row_Transaccion = mysql_fetch_assoc($Transaccion);
  }
?>
      </select>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<table border="1" align="left">
  <tr>
    <td width="100">Id rol </td>
    <td width="200">Descripcion rol </td>
    <td width="100">Id transacci&ograve;n </td>
    <td width="250">Descripci&ograve;n transacci&ograve;n </td>
  </tr>
  <?php do { ?>
    <tr>
      <td><span class="Estilo1"><?php echo $row_Rol_Trans['ID_ROL']; ?></span></td>
      <td><span class="Estilo1"><?php echo $row_Rol_Trans['DES_ROL']; ?></span></td>
      <td><span class="Estilo1"><?php echo $row_Rol_Trans['ID_TRANSACCION']; ?></span></td>
      <td><span class="Estilo1"><?php echo $row_Rol_Trans['DES_TRANSACCION']; ?></span></td>
    </tr>
    <?php } while ($row_Rol_Trans = mysql_fetch_assoc($Rol_Trans)); ?>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>
<table border="0" width="50%">
  <tr>
    <td width="23%" align="center"><?php if ($pageNum_Rol_Trans > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Rol_Trans=%d%s", $currentPage, 0, $queryString_Rol_Trans); ?>">Primero</a>
          <?php } // Show if not first page ?>
    </td>
    <td width="31%" align="center"><?php if ($pageNum_Rol_Trans > 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_Rol_Trans=%d%s", $currentPage, max(0, $pageNum_Rol_Trans - 1), $queryString_Rol_Trans); ?>">Anterior</a>
          <?php } // Show if not first page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_Rol_Trans < $totalPages_Rol_Trans) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Rol_Trans=%d%s", $currentPage, min($totalPages_Rol_Trans, $pageNum_Rol_Trans + 1), $queryString_Rol_Trans); ?>">Siguiente</a>
          <?php } // Show if not last page ?>
    </td>
    <td width="23%" align="center"><?php if ($pageNum_Rol_Trans < $totalPages_Rol_Trans) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_Rol_Trans=%d%s", $currentPage, $totalPages_Rol_Trans, $queryString_Rol_Trans); ?>">&Uacute;ltimo</a>
          <?php } // Show if not last page ?>
    </td>
  </tr>
</table>
</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Rol);

mysql_free_result($Transaccion);

mysql_free_result($Rol_Trans);
?>
